package cloud.lysky.game.gamesampe.component;

import com.almasb.fxgl.entity.component.Component;
import io.swagger.v3.oas.annotations.media.Schema;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;

@Schema(description = "生命值组件")
public class HealthComponent extends Component {
    @Schema(description = "最大生命值")
    private final IntegerProperty maxHP = new SimpleIntegerProperty();

    @Schema(description = "当前生命值")
    private final IntegerProperty HP = new SimpleIntegerProperty();
    public HealthComponent(int max) {
        maxHP.set(max);
        HP.set(max);
    }
    public void damage(int val) {
        HP.set(Math.max(0, HP.get() - val));
    }
    public void heal(int val)   {
        HP.set(Math.min(getMaxHP(), HP.get() + val));
    }
    public void setToMax()  {
        HP.set(getMaxHP());
    }
    public int getHp() {
        return HP.get();
    }
    public int getMaxHP() {
        return maxHP.get();
    }
    public IntegerProperty hpProperty() {
        return HP;
    }
    public IntegerProperty maxHPProperty() {
        return maxHP;
    }
}
